package com.ruoyi.quantify.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.quantify.domain.QuantifyRule;
import com.ruoyi.quantify.service.IQuantifyRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 量化考核规则Controller
 * 
 * @author yepanpan
 * @date 2021-05-14
 */
@Api("量化考核规则管理")
@RestController
@RequestMapping("/quantify/rule")
public class QuantifyRuleController extends BaseController
{
    @Autowired
    private IQuantifyRuleService quantifyRuleService;

    /**
     * 查询量化考核规则列表
     */
    @ApiOperation("查询量化考核规则列表")   
    @GetMapping("/select")
    public TableDataInfo select(QuantifyRule quantifyRule)
    {
    	quantifyRule.setStatus("1");
        List<QuantifyRule> list = quantifyRuleService.selectQuantifyRuleList(quantifyRule);
        return getDataTable(list);
    }
    
    /**
     * 查询量化考核规则列表
     */
    @ApiOperation("查询量化考核规则列表")   
    @PreAuthorize("@ss.hasPermi('quantify:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuantifyRule quantifyRule)
    {
        startPage();
        List<QuantifyRule> list = quantifyRuleService.selectQuantifyRuleList(quantifyRule);
        return getDataTable(list);
    }

    /**
     * 导出量化考核规则列表
     */
    @ApiOperation("导出量化考核规则列表")    
    @PreAuthorize("@ss.hasPermi('quantify:rule:export')")
    @Log(title = "量化考核规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuantifyRule quantifyRule)
    {
        List<QuantifyRule> list = quantifyRuleService.selectQuantifyRuleList(quantifyRule);
        ExcelUtil<QuantifyRule> util = new ExcelUtil<QuantifyRule>(QuantifyRule.class);
        return util.exportExcel(list, "rule");
    }

    /**
     * 获取量化考核规则详细信息
     */
    @ApiOperation("获取量化考核规则详细信息")
    @ApiImplicitParam(name = "id", value = "量化考核规则ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('quantify:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(quantifyRuleService.selectQuantifyRuleById(id));
    }

    /**
     * 新增量化考核规则
     */
    @ApiOperation("新增量化考核规则")
    @PreAuthorize("@ss.hasPermi('quantify:rule:add')")
    @Log(title = "量化考核规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuantifyRule quantifyRule)
    {
        return toAjax(quantifyRuleService.insertQuantifyRule(quantifyRule));
    }

    /**
     * 修改量化考核规则
     */
    @ApiOperation("修改量化考核规则")  
    @PreAuthorize("@ss.hasPermi('quantify:rule:edit')")
    @Log(title = "量化考核规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuantifyRule quantifyRule)
    {
        return toAjax(quantifyRuleService.updateQuantifyRule(quantifyRule));
    }

    /**
     * 删除量化考核规则
     */
    @ApiOperation("删除量化考核规则")
    @ApiImplicitParam(name = "id", value = "量化考核规则ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('quantify:rule:remove')")
    @Log(title = "量化考核规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quantifyRuleService.deleteQuantifyRuleByIds(ids));
    }
}
